function Ywkhfx(){
$("#dataregion").height($(window).height()-50);
$(".chartdiv").width($(window).width()/3-20).height(($(window).height()-50)/2-10)
	this.form=this.InitEleUI();
	$("#year").val($("#hidyear").val());
	$("#month").val($("#hidmonth").val());
	this.form.render('select');
	
	this.InitOrg();
	this.GetStatisData();
	//this.GetStatisDataDw();
	this.GetStatisYearDw();
}

Ywkhfx.prototype.InitEleUI=function(){
	var form;
	layui.use('form', function(){
       form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
       
       form.on('select(tempid)', function (data) {  
    	   $("#hidtempid").val(data.value);  
    	   vYwkhfx.GetStatisData();
       }); 
       
     
       
      
	   form.render();
	});  
	return form;
}

Ywkhfx.prototype.InitOrg = function() {
	var comboboxm=$("#orgid").ligerComboBox({
		valueField : 'orgid',
		textField : 'orgname',
		selectBoxWidth : 250,
		selectBoxHeight:250,
		treeLeafOnly:false,
		valueFieldID:"hid",
		tree: {url : '../common/get_org_list?orgtype=0',
			checkbox: false, 
			nodeWidth:150,
			ajaxType: 'get', 
			idFieldName: 'orgid',
			textFieldName:"orgname",
			idField:"orgid",
        	parentIDField:"orgparentid"
		},
		onSelected : function(orgid, orgname) {// id为空值，name为选择的值
			$("#hidszdw").val(orgid);
			$("#hidorgname").val(orgname);
			//vYwkhfx.GetStatisDataDw();
			vYwkhfx.GetStatisYearDw();
		},
		width : 250
	});
	return comboboxm;
}



Ywkhfx.prototype.GetStatisData=function(){
	$("#orgname").html($("#hidorgname").val());
	$.ajax({
		type:"GET",
		url:"getywkhdata",
		data:{year:$("#hidyear").val(),month:$("#hidmonth").val(),szdw:$("#hidszdw").val(),tempid:$("#hidtempid").val()},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				if(data.items.groupmap){
					if(data.items.ywmap){
						var ywbject=data.items.ywmap;
						var groupbject=data.items.groupmap;
						for(k=0;k<groupbject.length;k++){
							var orgdata=[];
							var scoreata=[];
							for(i=0;i<ywbject.length;i++){
								if(ywbject[i].groupid==groupbject[k].groupid){
									orgdata.push(ywbject[i].orgname.replace('派出所',''));
									scoreata.push(Math.ceil(ywbject[i].score));
								}
							}
							InitChats(orgdata,scoreata,groupbject[k].groupid);
						}
					}
				}
				//InitChats(['12','13'],[1,2],42);
			}
		}
	})
}


Ywkhfx.prototype.GetStatisDataDw=function(){
	$("#orgname").html($("#hidorgname").val());
	$.ajax({
		type:"GET",
		url:"getywkhdatadw",
		data:{year:$("#hidyear").val(),month:$("#hidmonth").val(),szdw:$("#hidszdw").val(),tempid:$("#hidtempid").val()},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
					if(data.items.ywmapdw){
						var ymdata=[1,2,3,4,5,6,7,8,9,10,11,12];
						var ywbject=data.items.ywmapdw;
						var scoreata=[];
						for(l=0;l<ymdata.length;l++){
							var mvalue=0;
							if(ywbject.length>0){
								for(k=0;k<ywbject.length;k++){
									if(ywbject[k].monthstr==ymdata[l]){
										mvalue=Math.ceil(ywbject[k].score);
									}
								}
							}
							scoreata.push(mvalue);
						}
					   InitChatsOrg(scoreata);
					}
				}
			}
	})
}




Ywkhfx.prototype.GetStatisYearDw=function(){
	$("#orgname").html($("#hidorgname").val());
	$.ajax({
		type:"GET",
		url:"getywkhyeardw",
		data:{szdw:$("#hidszdw").val(),tempid:$("#hidtempid").val()},
		beforeSend:function(XHR){

		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
					if(data.items.ywmapdw){
						var ymdata=[2015,2016,2017,2018,2019,2020,2021,2022];
						var ywbject=data.items.ywmapdw;
						var scoreata=[];
						var maxindex=0;
						for(l=0;l<ymdata.length;l++){
							var mvalue=-1;
							if(ywbject.length>0){
								for(k=0;k<ywbject.length;k++){
									if(ywbject[k].yearstr==ymdata[l]){
										mvalue=ywbject[k].rank;
										if(maxindex<mvalue){
											maxindex=mvalue;
										}
									}
								}
							}
							if(mvalue==-1){
								scoreata.push('');
							}
							else{
								scoreata.push(mvalue);
							}

						}
						InitChatsOrgYear(scoreata,maxindex);
					}
				}
			}
	})
}

var vYwkhfx;
$(function () {
	vYwkhfx = new Ywkhfx();
})


Ywkhfx.prototype.Rehref =function(){
    window.location.href="../workass/work_kp_look";
}

function InitChats(orgdata,scoreata,groupid){
	$("#group_"+groupid).width($(window).width()/3-10);
	$("#group_"+groupid).height(($(window).height()/2-55));
	//alert(JSON.stringify(scoreata));
	var myChart = echarts.init(document.getElementById("group_"+groupid));
	option = {
		    tooltip: {
		        trigger: 'axis',
		        axisPointer: {
		           // type: 'shadow'
		        },
		        backgroundColor:'#3187c2'
		       	
		    },
		    grid:{
                x:50,
                y:50,
                x2:20,
                y2:35,
               
                borderWidth:1
            },
		    toolbox: {
		        show: true,
		        feature: {
		            //saveAsImage: {}
		        }
		    },
		    xAxis:  {
		        type: 'category',
		        boundaryGap: true,
		        data: orgdata,
		        axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#aadeff'
                    },
                    interval:0
                    ,rotate:320
                },
                axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    }
		    },
		    yAxis: {
		        type: 'value',
		        show: true,
		        axisLabel: {
		            formatter: '{value}',
		            color: '#61a6e7'
		        },
		        axisPointer: {
		            snap: true
		        },
		        splitLine: {           // 分隔线
			        show: true,        // 默认显示，属性show控制显示与否
			        lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
			            color: ['#2180c5'],
			            width: 1,
			            type: 'solid'
			        }
			    },
			    splitArea: {           // 分隔区域
			        show: true,       // 默认不显示，属性show控制显示与否
			        areaStyle: {       // 属性areaStyle（详见areaStyle）控制区域样式
			            color: ['#25619f','none']
			        }
			    },
			    axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    },
			    min:0,
		        max:100,
		        minInterval:25
		    },
		    series: [
		        {
		            name:'分 ',
		            type:'bar',
		            smooth: true,
		            itemStyle : {  
                        normal : {  
                        	 color: new echarts.graphic.LinearGradient(
                                     0, 0, 0, 1,
                                   [
                                       {offset: 0, color: '#3899ff'},   // {offset: 0, color: '#2FDE80'},   
                                       {offset: 1, color: '#71effd'}//  {offset: 1, color: '#2FDECA'}
                                   ])
  
                        }  
                    }, 
                    barWidth : 18,
		            data: scoreata
		        }
		    ]
		};
	 myChart.setOption(option);
	
}


function InitChatsOrg(yeardata){
	$("#ChartOrg").width($(window).width()/3-10);
	$("#ChartOrg").height(($(window).height()/2-55));
	var myChart = echarts.init(document.getElementById('ChartOrg'));
	option = {
			 tooltip : {
			        trigger: 'axis',
			        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
			            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			        }
			    },
		    xAxis: { type: 'category',
		        boundaryGap: false,
		        data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
		        axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#aadeff'
                    }
                },
                axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    }
		    	
		       
		    },
		    yAxis: {
		    	type: 'value'
			        ,axisLabel: {
	                    show: true,
	                    textStyle: {
	                        color: '#aadeff'
	                    }
	                },
	                axisTick:{
				    	show:false
				    },
				    axisLine:{
				    	show:false
				    },
				    splitLine: {           // 分隔线
				        show: true,        // 默认显示，属性show控制显示与否
				        lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
				            color: ['#4170a8'],
				            width: 1,
				            type: 'solid'
				        }
				    },
				    splitArea: {           // 分隔区域
				        show: true,       // 默认不显示，属性show控制显示与否
				        areaStyle: {       // 属性areaStyle（详见areaStyle）控制区域样式
				            color: ['#305d94','none']
				        }
				    },
				    min:0,
			        max:1000,
			        minInterval:100
		    },
		    grid: {
		        left: 10,
		        right: 20,
		        bottom: 5,
		       
		        containLabel: true
		    },
		    series: [{
		        data: yeardata,
		        type: 'line',
		        itemStyle : {  
                    normal : {  
                    	 color:'#00FF00',  
                         lineStyle:{  
                             color:'#825c8b'  
                         }    
                    }  
                },
                symbolSize: 8,//拐点大小
		        areaStyle: { normal : {  
		                        	 color: new echarts.graphic.LinearGradient(
		                                     0, 0, 0, 1,
		                                   [
		                                      {offset: 0, color: 'rgba(38,98,160,0.3)'},   // {offset: 0, color: '#2FDE80'},   
		                                      {offset: 1, color: 'rgba(250,250,250,0.3)'}//  {offset: 1, color: '#2FDECA'}
		                                      
		                                   ])
		  
		                        } 
		                        }
		    }]
		};

	myChart.setOption(option);
}









function InitChatsOrgYear(yeardata,maxindex){
	$("#ChartOrg").width($(window).width()/3-10);
	$("#ChartOrg").height(($(window).height()/2-55));
	var myChart = echarts.init(document.getElementById('ChartOrg'));
	option = {
			 tooltip : {
			        trigger: 'axis',
			        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
			            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			        },
			        backgroundColor:'#3187c2',
			        textStyle: {
			              fontWeight: "normal",
			              color: "#aadeff",
			              fontSize: 8
			        },
			        formatter: function(params) {
	                    var result = '';
	                    params.forEach(function (item) {
	                    	//alert(JSON.stringify(item))
							if(item.value>0){
								 result += "   "+item.marker +item.name+"年：     第 "+ item.value +" 名";
							}

	                    });
	                    return result;
	                }

			    },



		    xAxis: { type: 'category',
		        boundaryGap: false,
		        data: ['2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022'],
		        axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#aadeff'
                    },
                    interval:0
                },
                axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    }



		    },
		    yAxis: {
		    	inverse:true,
		    	type: 'value'
			        ,axisLabel: {
	                    show: true,
	                    textStyle: {
	                        color: '#aadeff'
	                    }
	                },
	                axisTick:{
				    	show:false
				    },
				    axisLine:{
				    	show:false,
				    	onZero: false
				    },
				    splitLine: {           // 分隔线
				        show: true,        // 默认显示，属性show控制显示与否
				        lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
				            color: ['#4170a8'],
				            width: 1,
				            type: 'solid'
				        }
				    },
				    splitArea: {           // 分隔区域
				        show: true,       // 默认不显示，属性show控制显示与否
				        areaStyle: {       // 属性areaStyle（详见areaStyle）控制区域样式
				            color: ['#305d94','none']
				        }
				    },
				    min:1,
			        max:(maxindex+1)%2==0?(maxindex+1):(maxindex+2)
			        ,minInterval:1
		    },
		    grid: {
		        left: 10,
		        right: 20,
		        bottom: 5,

		        containLabel: true
		    },
		    series: [{
		        data: yeardata,
		        type: 'line'
		        ,itemStyle : {
                    normal : {
                    	 color:'#00FF00',
                    	 borderColor:'red',
                         lineStyle:{
                             color:'#825c8b',
                             width:4
                         }

                    }
                },
                symbolSize: 12//拐点大小
//		        ,areaStyle: { normal : {
//		                        	 color: new echarts.graphic.LinearGradient(
//		                                     0, 0, 0, 1,
//		                                   [
//		                                      {offset: 0, color: 'rgba(38,98,160,0.3)'},   // {offset: 0, color: '#2FDE80'},
//		                                      {offset: 1, color: 'rgba(250,250,250,0.3)'}//  {offset: 1, color: '#2FDECA'}
//
//		                                   ])
//
//		                        }
//		                        }
		    }]
		};






	myChart.setOption(option);
}